package com.jmp.push;

import one.stand.util.AssertUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Map;

@Configuration
@EnableConfigurationProperties(OnePushProperties.class)
public class PushAutoConfiguration {
    @Autowired
    private OnePushProperties onePushProperties;

    @Bean
    public PushClient pushClient() {
        AssertUtil.nonNull(onePushProperties.getClientMap(), "push config must not be null");
        ComplexPushClient pushClient = new ComplexPushClient(onePushProperties);
        for (Map.Entry<String, OnePushProperties.OnePush> entry : onePushProperties.getClientMap().entrySet()) {
            pushClient.addClient(new DefaultPushClient(entry.getValue()));
        }
        return pushClient;
    }

}
